
function initWordUploader(wordUploader,arr) {
	if(!!wordUploader) {
		removeAllWordFiles(wordUploader,arr.uploader_box);
		wordUploader.reset();
		return wordUploader;
	}
    var $ = jQuery,    // just in case. Make sure it's not an other libaray.
    $wrap = $(arr.uploader_box),
    // 实例化
    wordUploader = WebUploader.create({
    	formData:{
        	'_token':$('meta[name="csrf-token"]').attr('content')
        },
        pick: {
            id: arr.filePicker,
            label: '点击选择文件'
        },
        auto:true,
        dnd: arr.uploader_box+' .queueList',
        paste: document.body,
        accept: {
            //title: 'Images',
            extensions: 'doc,docx',
            mimeTypes: 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        },

        // swf文件路径
        swf:'/plugin/web_uploader/Uploader.swf',

        disableGlobalDnd: true,

        chunked: true,
        // server: 'http://webuploader.duapp.com/server/fileupload.php',
        server: '/member/word_upload',
        fileNumLimit: 1,
        fileSizeLimit: 5 * 1024 * 1024,    // 200 M
        fileSingleSizeLimit: 1 * 1024 * 1024    // 50 M
    });
    
    wordUploader.on( 'fileQueued', function( file ) {
    	$list = $(arr.uploader_box+" .filelist");
        $list.append( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">等待上传...</p>' +
        '</div>' );
        $(arr.uploader_box+" .queueList").hide();
        
    });
    wordUploader.on( 'uploadSuccess', function( file ,response) {
    	$("#"+file.id).remove();
    	arr.successHanlder(file,response);
    });
    wordUploader.on( 'uploadComplete', function( file ) {
        arr.completeHanlder();
    });
    wordUploader.on( 'uploadProgress', function( file, percentage ) {
        var $li = $( '#'+file.id ),
        $percent = $li.find('.progress .progress-bar');

        // 避免重复创建
        if ( !$percent.length ) {
            $percent = $('<div class="progress progress-striped active">' +
              '<div class="progress-bar" role="progressbar" style="width: 0%">' +
              '</div>' +
            '</div>').appendTo( $li ).find('.progress-bar');
        }
        $li.find('p.state').text('上传中');
        $percent.css( 'width', percentage * 100 + '%' );
    });
    return wordUploader;
};

function removeAllWordFiles(uploader,uploader_box){
	var files = uploader.getFiles();
	for(var i in files){
		uploader.removeFile(files[i]);
	}
	$(uploader_box+" .queueList").show();
}

